import Taro from '@tarojs/taro'
import {AtButton} from "taro-ui"
import {Image, View} from "@tarojs/components";
import {authLogin} from "./service";
import PleaseAuth from './auth.svg'
import './index.scss'

export default class Index extends Taro.Component {

  config = {
    navigationBarTitleText: '欢迎登录'
  };

  constructor(props) {
    super(props);
    this.state = {}
  }

  componentDidMount() {
  }

  doGetUserInfo(event) {
    const {userInfo} = event.detail;
    // 同意授权
    if (userInfo) {
      authLogin(userInfo, true);
    } else {
      Taro.showToast({
        title: '请授权以使用更多功能',
        icon: 'none',
        duration: 2000
      })
    }
  }

  render() {
    return (
      <View className='auth'>
        <View className='at-row at-row__justify--center' style={{margin: '20PX 0'}}>
          <Image src={PleaseAuth} style={{width: '240PX', height: '240PX'}} />
        </View>
        <AtButton type='primary' circle full openType='getUserInfo'
                  onGetUserInfo={this.doGetUserInfo.bind(this)}
        >
          授权登录
        </AtButton>
      </View>
    )
  }
}
